layui.use(['form','layer','table','laytpl'],function() {
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        laytpl = layui.laytpl,
        table = layui.table;
})

/**
 * 回复评论。
 * @param obj
 */
function replyByComment(obj) {
    var replyToId = $(obj).parents(".comment-show-con").find("input[Id='replyFromId']").val();
    var replyFromId = $(obj).parents(".comment-show-con").find("input[Id='replyToId']").val();
    var replyId = $(obj).parents(".comment-show-con").find("input[Id='replyId']").val();
    var userId = $("#hId").val();
    if (replyToId == userId){
        layer.msg("自己不能给自己回复",{offset:'300px' });
    } else  {
        layer.prompt({
            formType: 2,
            title: '请输入要回复的内容',
            offset: '300px',
            area: ['400px', '60px'] //自定义文本域宽高
        }, function(value, index, elem){
             $.ajax({
                 url : "saveReply",
                 type : "GET",
                 data : {
                     replyFromId : replyFromId,
                     replyToId : replyToId,
                     replyId : replyId,
                     content : value
                 },
                 success : function (result) {
                     if (result.code == 100){
                         layer.msg("回复成功",{offset:'300px' });
                         var s = cloneReply(result.extend.reply);
                         $(obj).parents(".comment-show-con").after(s);
                     } else {
                         layer.msg("回复失败，未知异常联系管理员",{offset:'300px' });
                     }
                 }
             });
            layer.close(index);
        });
    }

}
function replyByReply(obj) {
    var replyToId = $(obj).parents(".comment-show-con").find("input[Id='replyFromId']").val();
    var replyFromId = $(obj).parents(".comment-show-con").find("input[Id='replyToId']").val();
    var replyId = $(obj).parents(".comment-show-con").find("input[Id='replyId']").val();
    var userId = $("#hId").val();
    if (replyToId == userId){
        layer.msg("自己不能给自己回复",{offset:'300px' });
    } else  {
        layer.prompt({
            formType: 2,
            title: '请输入要回复的内容',
            offset: '300px',
            area: ['400px', '60px'] //自定义文本域宽高
        }, function(value, index, elem){
            $.ajax({
                url : "saveReply",
                type : "GET",
                data : {
                    replyFromId : replyFromId,
                    replyToId : replyToId,
                    replyId : replyId,
                    content : value
                },
                success : function (result) {
                    if (result.code == 100){
                        layer.msg("回复成功",{offset:'300px' });
                        var s = cloneReply(result.extend.reply);
                        $(obj).parents(".comment-show-con").after(s);
                    } else {
                        layer.msg("回复失败，未知异常联系管理员",{offset:'300px' });
                    }
                }
            });
            layer.close(index);
        });
    }
}
